package com.huanxing.cloud.common.storage.handler.impl;

import com.huanxing.cloud.common.storage.entity.StorageConfig;
import com.huanxing.cloud.common.storage.handler.HxUploadFileHandler;
import com.huanxing.cloud.upms.common.dto.SysStorageConfigDTO;

import java.io.File;

public abstract class AbstractUploadFileHandler implements HxUploadFileHandler {

	@Override
	public String uploadFile(SysStorageConfigDTO sysStorageConfig, File file) {
		StorageConfig storageConfig = validateRequest(sysStorageConfig);
		return doUploadFile(storageConfig, file);
	}

	public abstract String doUploadFile(StorageConfig storageConfig, File file);

	private StorageConfig validateRequest(SysStorageConfigDTO sysStorageConfig) {
		StorageConfig storageConfig = new StorageConfig();
		storageConfig.setAccessKeyId(sysStorageConfig.getAccessKey());
		storageConfig.setAccessKeySecret(sysStorageConfig.getAccessSecret());
		storageConfig.setBucket(sysStorageConfig.getBucket());
		storageConfig.setEndpoint(sysStorageConfig.getEndpoint());
		storageConfig.setDir(sysStorageConfig.getDir());
		return storageConfig;
	}

}
